package prjtgl.util;

import java.util.HashMap;
import java.util.Map;
import javax.xml.ws.http.HTTPException;
import org.zkoss.bind.BindUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.GenericRichlet;
import org.zkoss.zk.ui.Page;

/**
 * Permet d'utiliser les URL pour afficher la bonne page
 * @author amirouche
 */
public class Servlet extends GenericRichlet {

	@Override
	public void service(Page page) throws Exception {

		Map<String, Object> args = new HashMap();
		Executions.createComponents("/index.zul", null, args);
		if (!page.getRequestPath().equals("/")) {
			String realPath = page.getRequestPath();
			realPath = realPath.replaceAll("_", "/");
			if(!realPath.equals("")){
				realPath += ".zul";
				args.put("content", realPath);
				BindUtils.postGlobalCommand(null, null, "changePage", args);
			}
		}
	}
}
